/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component} from 'react';
import {
  Form, Input, Radio, Select, Icon,
  Upload, Descriptions, DatePicker, Button, Modal,
} from 'antd';
import {connect} from 'dva';
import moment from 'moment'
import request from '@/utils/request';
import BuildModalTitle from "@/components/BuildModalTitle";
import {afterCloseModal} from "@/utils/utils";
import SelectUser from "@/pages/InnerAddressBook/SelectUser";
const FormItem = Form.Item;
const { TextArea } = Input;
const RadioGroup = Radio.Group;
const Option = Select.Option;
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      fileList:[],
      all_department:[],
      selectUser:{
        username:this.props.editRecord?this.props.editRecord.applicant.name:'',
        id:this.props.editRecord?this.props.editRecord.applicant.id:'',
      }
    };
  }
  fetchAllDepartments=()=>{
    const that = this;
    request(`/all_departments`, {
      method: 'GET',
      params: {
        order_direction: 'desc',
      },
    }).then((response) => {
      if (response.status === 200) {
        that.setState({
          all_department: response.data.data,
        });
      }
    });
  }
  componentDidMount() {
    this.fetchAllDepartments();
  }
  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 6},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 15},
      }
    };

    const {getFieldDecorator} = this.props.form;

    return (
      <div>
        <Form>
          <Descriptions  column={4}   className={'blue-descriptions'} title={''} bordered>
            <Descriptions.Item span={4} label="申请人">
              <div style={{positin:'relative'}}>
                <Input disabled={true} value={this.state.selectUser.username}/>
                {
                  <Button style={{position:'absolute',right:'42px'}} type={'primary'} onClick={()=>{
                    if(this.props.editRecord &&this.props.editRecord.status===1){
                      this.setState({
                        // username:this.props.form.getFieldValue('name'),
                        selectModal:true
                      })
                    }
                    if(!this.props.editRecord){
                      this.setState({
                        // username:this.props.form.getFieldValue('name'),
                        selectModal:true
                      })
                    }

                  }}>选择</Button>
                }

              </div>
            </Descriptions.Item>
            <Descriptions.Item label="立项原因"  span={4}>
              {getFieldDecorator('lxyy', {
                initialValue: this.props.editRecord?this.props.editRecord.parameters.lxyy:'',
              })(
                <TextArea disabled={Boolean(this.props.editRecord&&this.props.editRecord.status!==1)}  rows={3}  />
              )}
            </Descriptions.Item>
            <Descriptions.Item label="需求说明"  span={4}>
              {getFieldDecorator('xqsm', {
                initialValue: this.props.editRecord?this.props.editRecord.parameters.xqsm:'',
              })(
                <TextArea disabled={Boolean(this.props.editRecord&&this.props.editRecord.status!==1)}   rows={3}  />
              )}
            </Descriptions.Item>

          </Descriptions>
        </Form>
        <Modal
          title={<BuildModalTitle visible={this.state.selectModal} modalClass="selectModal"
                                  title={`选择申请人`} />}
          destroyOnClose
          visible={this.state.selectModal}
          centered
          width={900}
          onOk={this.handleChangeStatus}
          className="selectModal"
          afterClose={() => {
            afterCloseModal(); // destroyOnClose需要
          }}
          onCancel={() => {
            this.setState({ selectModal: false});
          }}
        >
          <SelectUser refleshDepartments={this.SelectUser} username={this.state.username} selectUser={(row)=>{
            this.setState({
              selectModal: false,
              selectUser:row
            })
          }}
          />

        </Modal>
      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);
